package com.example.chamberlainserver.controller;

import com.example.chamberlainserver.Service.STSTokenService;
import com.example.chamberlainserver.Vo.Response.ApiResponse;
import com.example.chamberlainserver.dto.STSTokenResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * STS临时凭证控制器
 */
@RestController
@RequestMapping("/api")
public class STSTokenController {

    @Autowired
    private STSTokenService stsTokenService;

    /**
     * 获取STS临时凭证
     * @return STS临时凭证响应
     */
    @GetMapping("/sts-token")
    public ResponseEntity<ApiResponse<STSTokenResponse>> getSTSToken() {
        try {
            STSTokenResponse stsToken = stsTokenService.generateSTSToken();
            return ResponseEntity.ok(ApiResponse.success(stsToken));
        } catch (Exception e) {
            return ResponseEntity.status(500).body(ApiResponse.error(500, "获取STS临时凭证失败: " + e.getMessage()));
        }
    }
}